<?php
ini_set('display_errors', 'On');
//error_reporting(0);
session_start();


/* =====Directory Folder=== */
defined("ADMIN_FOLDER") ? null : define("ADMIN_FOLDER", "admin");
defined("DS") ? null : define("DS", DIRECTORY_SEPARATOR);
defined("LIB_PATH") ? null : define("LIB_PATH", __DIR__);

defined("FRONT_SITE_DIR") ? null : define("FRONT_SITE_DIR", str_replace(DS . "libraryfiles", "", LIB_PATH));
defined("BACK_SITE_DIR") ? null : define("BACK_SITE_DIR", FRONT_SITE_DIR . DS . ADMIN_FOLDER);

require_once 'function.php';
if (!defined('base_url')) {
	define('base_url', 'http://localhost/psarinternet/');
	define('base_url_admin', 'http://localhost/psarinternet/');

    /* for dir upload for other */

}

$thsfile = str_replace('\\', '/', __FILE__);
if (isset($_SERVER['DOCUMENT_ROOT'])) {
    $droot = $_SERVER['DOCUMENT_ROOT'];
} else {
    $localpath = getenv("SCRIPT_NAME");
    $absolutepath = realpath(basename(getenv("SCRIPT_NAME")));


    $absolutepath = str_replace("\\", "/", $absolutepath);
    $droot = substr($absolutepath, 0, strpos($absolutepath, $localpath));
}

if (!isset($sp))
    $sp = explode("/", $_SERVER['PHP_SELF']);

if ($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "192.168.1.25") {
    $sp[1] = '/' . $sp[1];
}
else
    $sp[1] = '';

$w_root = $_SERVER['SERVER_NAME'] . $sp[1];
$w_root = str_replace('//', '/', $w_root);
$w_root = str_replace('\\\\', '\\', $w_root);
$s_root = $_SERVER['DOCUMENT_ROOT'] . $sp[1];
$s_root = str_replace('//', '/', $s_root);
$s_root = str_replace('\\\\', '\\', $s_root);

define('W_ROOT', "http://" . $w_root);
define('S_ROOT', $s_root);


function url($domain, $url, $rules) {
    $url = parse_url($url);
    parse_str($url['query'], $url['query']);
    $argNames = array_keys($url['query']);
    foreach ($rules as $rule) {
        if ($rule[0] == $url['path'] && array_keys($rule[1]) == $argNames) {
            $newUrl = $rule[2];
            foreach ($rule[1] as $name => $pattern) {
                if (!preg_match('/' . addcslashes($pattern, '/') . '/', $url['query'][$name], $match)) {
                    continue 2;
                }
                $newUrl = str_replace('<' . $name . '>', $match[0], $newUrl);
            }
            return $domain . $newUrl;
        }
    }
    return $url;
}

define('TMP_ADMIN_PATH', S_ROOT . '/templates/admin_template.php');
define('TMP_USER_PATH', S_ROOT . '/templates/template.php');
define('TMP_SELL_PATH', S_ROOT . '/company/column.php');
define('TMP_SELLER_PATH', S_ROOT . '/seller/index.php');
define('TMP_ACCOUNT_PATH', S_ROOT . '/account/index.php');
define('TMP_SELL_ADMIN_PATH', S_ROOT . '/company/product/template.php');
define('W_IMAGES_DIR', base_url . 'images/');
define('S_IMAGES_DIR', S_ROOT . '/images/');
define('W_S_IMAGES_DIR', base_url . 'product/images/');
define('W_S_IMAGES_DIR_THUMB', base_url . 'product/images/thumb/');
define('S_S_IMAGES_DIR', S_ROOT . '/product/images/');
define('ACCEPT_IMAGE_EXT', ".jpg,.png,.ping,.jpeg,.gif");
define('ACCEPT_FILE_EXT', ".jpg,.png,.ping,.jpeg,.gif,.pdf,.doc,.flv,.zip,.rar");
define('MAX_UPLOAD_SIZE', 1048576);
define('MAX_UPLOAD_FILE_SIZE', 3145728);
define('MAX_THUM_IMG_W', 100);
define('MIN_THUM_IMG_W', 75);
define('MAX_SMALL_IMAGE_WIDTH', 500);
define('LIMIT_PRODUCT_WIDTH', true);
define('MAX_PRODUCT_IMAGE_WIDTH', 500);
define('THUMBNAIL_WIDTH', 150);
define('LIMIT_COMPANY_W', true);
define('MAX_COMPANY_IMG_W', 200);
define('MAX_COMPANY_THUMBIMG_W', 75);
define('NO_IMAGES_W', W_IMAGES_DIR . 'no_image_small.jpg');
define('NO_IMAGES_S', S_IMAGES_DIR . 'no_image_small.jpg');
define('UPLOAD_DIR', 'images/');
define('MENU_IMG_DIR', UPLOAD_DIR . 'menus/');
define('CONTENT_IMG_DIR', UPLOAD_DIR . 'contents/');
define('STAR_T', '<span class="note">*</span>');
define('POINT', '<img src=\"W_IMAGES_DIR /images/point.jpg\"/>');

$mosConfig_live_site = W_ROOT;
$mosConfig_absolute_path = S_ROOT;
$mosConfig_sitename = 'Website';

$site_title = isset($site_title) ? $site_title : 'Welcome to psarinternet.com';
$site_description = isset($site_description) ? $site_description : "";
$site_keywords = isset($site_keywords) ? $site_keywords : "";

define('MAX_RECORD_DISPLAY', 15);
define('MAX_NEWS_DISPLAYH', 10);
define('DISPLAY_NUMBER', '5,10,15,20,25,30,50');

require_once 'db-funct.php';
require_once 'common-funct.php';
require_once 'admin-funct.php';
require_once 'DbTable/initialize.php';
if (preg_match("/admin/", $_SERVER['PHP_SELF'])) {
    checkAdminUser();
}

if (preg_match("/buyer/", $_SERVER['PHP_SELF'])) {
    checkBuyerUser();
}
if (preg_match("/seller/", $_SERVER['PHP_SELF'])) {
    checkSellerUser();
    require_once 'seller.class.php';
}
$pageURL = $_SERVER["REQUEST_URI"];
$homepage = '/psardepo/';


$catelist = mysql_query("SELECT * FROM tblcategory");
$categories = array("Categories" => array());
while ($row = mysql_fetch_assoc($catelist)) {

    $menu_array[$row['id']] = array('id' => $row['id'], 'category_name' => $row['category_name'], 'parent_id' => $row['parent_id']);
}

function generate_menu($parent) {
    $has_childs = false;
    global $menu_array;



    foreach ($menu_array as $key => $value) {
        if ($value['parent_id'] == $parent) {

            if ($has_childs === false) {
                $has_childs = true;

                echo '<ul>';
                echo '<li class="selected home"><a href="' . W_ROOT . '">Home</a></li>';
            }
            $cat_p = isset($_GET['cat_id']) ? $_GET['cat_id'] : "";
            ?>
            <li class="menulink">
                <a href="<?php echo W_ROOT; ?>/product/?cat_p=<?php echo $value['id']; ?>"><?php echo $value['category_name'] ?></a>
                <?php
                generate_menu($key);

            echo '</li>';

        }

        if ($has_childs === true) {
            echo '<div class="last-li"></div></ul>';
        }
    }


function build_menu_home() {
	$menu = '';
	$has_childs = false;
	$result = mysql_query("SELECT * FROM tblcategory WHERE parent_id='0' AND status='1'");
	$menu = array();
	while ($row=mysql_fetch_assoc($result)) {
		$menu[] = $row;
	}
	return $menu;
}

function create_slug($string) {
    $string = preg_replace('/[��""!?,.!@�$%^&*{};:()]+/', '', $string);
    $string = strtolower($string);
    $slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
    return $slug;
}
}
?>
